#include"Polygons.h"

/////////////////
//include
/////////////////
#include"Octree.h"
#include"DeviceContext.h"
#include"PrimitiveDrawer.h"
/////////////////
//prottype
/////////////////

/////////////////
//const
/////////////////


Polygons::Polygons(Array<Triangle*> polygons)
{
	this->polygons = polygons;
}
Polygons::~Polygons()
{
}
TriCollInfo Polygons::GetCollisionLine(Vector3D start,Vector3D end,Vector3D offset_pos)
{
	float tmp_length = FLT_MAX;
	TriCollInfo info ;
	TriCollInfo tmp_info ;
	for(int i = 0;i<polygons.GetSize();i++)
	{
		polygons[i]->CollisionLine(tmp_info,start,end,offset_pos);

		if(tmp_info.is_collision)
		{
			if(tmp_length > (tmp_info.pos - start).Length())
			{
				info = tmp_info;
				tmp_length = (tmp_info.pos - start).Length();
			}
			
		}
	}
	return info;
}
void Polygons::Draw(DeviceContext* device_context,Vector3D offset_pos)
{
	for(int i = 0;i<polygons.GetSize();i++)
	{
		PrimitiveDrawer::DrawTriangle(device_context,offset_pos,polygons[i]->vertex[0],polygons[i]->vertex[1],polygons[i]->vertex[2]);
	}
}